import { defHttp } from '/@/common/util/axios';

enum Api {
  list = '/emp/hubTeamResult/getPage',
  header = '/emp/dynamicTable/getTeamResultHeader', //动态表头
  initSummary = '/emp/hubTeamResult/initSummary', //月度汇总接口
  publishSummary = '/emp/hubTeamResult/publishSummary', //按钮功能事件
  commit = '/emp/result/teamResult/commit', //月度汇总提交
  update = '/emp/hubTeamResult/updateBatch', //批量编辑保存
  getPeriodTree = '/emp/epmBasePeriod/periodTree', //考核周期树
  audit = '/emp/result/teamResult/audit', //月度汇总审核
  cancel = '/emp/result/teamResult/cancel', //通用退回接口
  modalHeader = '/emp/result/teamResult/getTeamResultDetailHeaders', //详情页里的动态表头
  modalList = '/emp/result/teamResult/getTeamResultDetail/findPage', //详情页里的列表
  importExcel = '/emp/hubTeamResult/importExcel',
  exportXls = '/emp/hubTeamResult/exportXls',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * author:lhw
 * description: 查询分摊模式
 * @params: @params 查询参数
 * date: 2023/2/13
 * lastModify: 2023/2/13
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * author:lhw
 * description: 查询动态表头
 * @params: @
 * date: 2023/2/16
 * lastModify: 2023/2/16
 */
export const getColumn = (params) => defHttp.post({ url: Api.header, params });

export const batchUpdate = (params) => defHttp.post({ url: Api.update, params });

/**
 * 按钮功能事件
 */
export const publishSummary = (params) => defHttp.post({ url: Api.publishSummary, params });

/**
 * 汇总初始化
 */
export const initSummary = (params) => defHttp.post({ url: Api.initSummary, params });

export const handleCommit = (params) => defHttp.post({ url: Api.commit, params });

export let PeriodTree = [];

export const getPeriodTree = () => {
  const params = {
    type: 'yearM',
  };
  return new Promise((resolve) => {
    defHttp.post({ url: Api.getPeriodTree, params }, { joinParamsToUrl: true }).then((res) => {
      PeriodTree = res;
      resolve(res);
    });
  });
};

export const getModalColumn = (params) => defHttp.post({ url: Api.modalHeader, params });

export const modalList = (params) => {
  return new Promise((resolve) => {
    defHttp.post({ url: Api.modalList, params }).then((res) => {
      resolve(res.detail);
    });
  });
};
